package com.macaline.aliyun.photo;

import com.aliyun.imagerecog20190930.models.RecognizeImageColorResponse;
import com.aliyun.tea.*;
import com.aliyun.teautil.Common;
import net.sf.json.JSONObject;

public class PhotoUtil {

    /**
    * 使用AK&SK初始化账号Client
    * @param accessKeyId
    * @param accessKeySecret
    * @return Client
    * @throws Exception
    */
    public static com.aliyun.imagerecog20190930.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
            // 您的 AccessKey ID
            .setAccessKeyId(accessKeyId)
            // 您的 AccessKey Secret
            .setAccessKeySecret(accessKeySecret);
            // 访问的域名
        config.endpoint = "imagerecog.cn-shanghai.aliyuncs.com";
        return new com.aliyun.imagerecog20190930.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        com.aliyun.imagerecog20190930.Client client = createClient("LTAIKo7viNUpnaUL", "deTBfqnOrPKenhfAYYhRYWeZIGveJZ");
        com.aliyun.imagerecog20190930.models.RecognizeImageColorRequest recognizeImageColorRequest = new com.aliyun.imagerecog20190930.models.RecognizeImageColorRequest()
            .setUrl("http://photo-color-warmjoy.oss-cn-shanghai.aliyuncs.com/1.jpg?Expires=1666938282&OSSAccessKeyId=TMP.3KiEhNsVr1XGjCmWe8VZHpt3ibaACx4Xqnqv2uA3r7Ks6fE7XoRw2JtbTXaDrMNb3ftgsakejvCG56jm1zp9fhD3b9PSfB&Signature=fi8Zm5%2BKXSae9h7xSr9EtmQhwSU%3D")
            .setColorCount(3);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // 复制代码运行请自行打印 API 的返回值
            RecognizeImageColorResponse recognizeImageColorResponse = client.recognizeImageColorWithOptions(recognizeImageColorRequest, runtime);
            JSONObject jsonObject = JSONObject.fromObject(recognizeImageColorResponse);
            System.out.println(jsonObject.toString());
        } catch (TeaException error) {
            // 如有需要，请打印 error
            String s = Common.assertAsString(error.message);
            System.out.println(s);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 如有需要，请打印 error
            String s = Common.assertAsString(error.message);
            System.out.println(s);
        }
    }
}
